<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document-admin</title>
</head>
<!-- 引入样式 -->
<link rel="stylesheet" href="../../plugins/element-ui/lib/theme-chalk/index.css"/>
<!--<link rel="stylesheet" href="../../styles/common.css" />-->
<link rel="stylesheet" href="../../styles/page.css" />
<body>
<div class="dashboard-container" id="admin-app">
    <div class="container">
        <div class="tableBar" style="justify-content: flex-start;">
            <el-input v-model="input" placeholder="请输入学生名" style="width: 250px;margin-right: 40px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
            <el-input v-model="input1" placeholder="请输入班级名" style="width: 250px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
        </div>
        <!--管理员分页展示table-->
        <el-table :data="tableData" stripe class="tableBox">
            <el-table-column prop="name" label="学生姓名"></el-table-column>
            <el-table-column prop="sid" label="学号"></el-table-column>
            <el-table-column prop="school" label="学校"></el-table-column>
            <el-table-column prop="major" label="专业"></el-table-column>
            <el-table-column prop="grade" label="入学年份"></el-table-column>
            <el-table-column prop="clazzName" label="班级名"></el-table-column>
            <el-table-column prop="status" label="状态"></el-table-column>
            <el-table-column prop="gone" label="去向"></el-table-column>
            <el-table-column fixed="right" label="操作" width="160" align="center">
                <template slot-scope="scope">
                    <el-button type="text" size="small" class="blueBug" @click="addAdminHandle(scope.row.id)">
                        查看详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--page-sizes 条目数 -->
        <el-pagination
                class="pageList"
                :page-sizes="[20,30,40,50]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
</body>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/lib/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/student.js"></script>
<script>
    new Vue({
        el: '#admin-app',
        data() {
            return {
                input: '',
                input1: '',
                counts: 0,
                page: 1,
                pageSize: 20,
                tableData : [],
                id : '',
                status : '',
            }
        },
        computed: {},

        /*vue初始化挂载函数*/
        created() {
            this.init();
            // alert(1439057691107037185);//js失去精度测试
            if(localStorage.getItem('userInfo')!=null){
                //获取当前登录管理员的账号，并赋值给模型数据
                this.user = JSON.parse(localStorage.getItem('userInfo')).username;
            }
        },
        mounted() {
        },
        methods: {
            async init () {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,
                    name: this.input ? this.input : undefined,
                    clazzName: this.input1 ? this.input1 : undefined
                };
                await getStudentList(params).then(res => {//res === res.data
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records || [];
                        this.counts = res.data.total
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 添加&修改跳转
            addAdminHandle (st) {
                if (st === 'add'){
                    window.parent.menuHandle({
                        id: '3',
                        url: '/back/page/student/add.html',
                        name: '添加学生'
                    },true)
                } else {
                    window.parent.menuHandle({
                        id: '3',
                        url: '/back/page/student/add.html?id='+st,//跳转到add.html页面并携带一个id参数
                        name: '查看学生详情'
                    },true)
                }
            },
            handleSizeChange (val) {
                this.pageSize = val;
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val;
                this.init()
            }
        }
    })
</script>
</html>